import EventEmitter from 'events'
import { GlobalKeyboardListener } from 'node-global-key-listener'
const listener = new GlobalKeyboardListener()

// 监听所有按键
listener.addListener((e) => {
  console.log(listener)
  console.log(`${e.name} ${e.state === 'DOWN' ? 'DOWN' : 'UP'}`)
})
const keyEmit = new EventEmitter()
const keyMap = new Map()
// 监听 Win+Space（Mac 为 Command+Space）
listener.addListener((e, down) => {
  if (e.state === 'DOWN' && e.name === 'SPACE' && (down['LEFT META'] || down['RIGHT META'])) {
    console.log('快捷键触发')
    if (keyMap.has(e.name)) {
      keyEmit.emit(e.name)
    }
    // return true // 阻止默认行为
  }
})
